/**
 * 修改密码窗口
 */
DC.front.win.ModifyUserInfoWin = function(params, config) {
	var muWin = this;
	
	var modifyUser_formPanel = new DC.front.ModifyUserFormPanel();
	
	DC.front.win.ModifyUserInfoWin.superclass.constructor.call(this, Ext.apply({
    	id : 'modify_userInfo_win',
    	title : 'Modify UserInfo',
    	width : 430,
    	height : 250,
        border : true,
        bodyBorder : true,
        layout : 'fit',
        modal : true,
        closeAction : 'close',
        items :[ modifyUser_formPanel ],
        buttons : [{
        	id : 'modify_userInfo_win_save_btn',
			text : 'Save',
			handler :function(){
				modifyUser_formPanel.modifyUserInfo();
			} 
		}, {
			text : 'Cancle',
			handler :function(){
				muWin.close();
			} 
		}]
    }, config ||{}));
};

Ext.extend(DC.front.win.ModifyUserInfoWin, Ext.Window, {
	
});

/**
 * 修改用户信息的表单
 */
DC.front.ModifyUserFormPanel = function(params, config) {
	var mufp = this;
	
	var mbool= true, fbool = false;
	if(DC.front.variable.SYS_CURRENTUSER.sex == '女') {
		mbool = false;
		fbool = true;
	}
	
	DC.front.ModifyUserFormPanel.superclass.constructor.call(this, Ext.apply({
            id: 'modifyUser_formPanel',
            header : false,
            labelWidth: 70,
            labelAlign: 'right',
            border : false,
            frame: true,
            buttonAlign : 'center',
            items: [{
            	layout : 'form',
            	defaultType : 'textfield',
            	defaults : {
                    width : 310
                },
            	items : [{
            		    id : 'modifyUser_formPanel_id',
		                name : 'userVOBean.id',
		                xtype : 'hidden',
		                value : DC.front.variable.SYS_CURRENTUSER.id
		            }, {
		            	id : 'modifyUser_formPanel_username',
		            	xtype : 'label',
		                name : 'userVOBean.username',
		                fieldLabel : 'User Name',
		                text : DC.front.variable.SYS_CURRENTUSER.username
		            }, {
		            	id: 'editUser_formPanel_realName',
		            	anchor : '68%',
		            	name: 'userVOBean.realName',
		                fieldLabel: 'Real Name',
		                value :  DC.front.variable.SYS_CURRENTUSER.realName,
		                maxLength: 100,
		                maxLengthText : 'The length of the Real Name cannot be more than 100.'
            	}]
            }, {
            	xtype : 'radiogroup',
            	fieldLabel : 'Gender',
            	anchor : '50%',
            	items : [ {
            		id : 'modifyUser_formPanel_gender_male',
        			name : 'userVOBean.sex',
        			boxLabel : 'Male',
        			checked : mbool,
        			value : '1'
        		}, {
        			id : 'modifyUser_formPanel_gender_female',
            		name : 'userVOBean.sex',
            		boxLabel : 'Female',
            		checked : fbool,
        			value : '0'
        		}]
            }, {
            	layout : 'form',
            	defaults: {
                    width: 310
                },
            	items : [{
            		id : 'modifyUser_formPanel_birthday',
            		xtype : 'datefield',
        			name : 'userVOBean.birthday',
        			anchor : '68%',
        			fieldLabel : 'Birthday',
        			format : 'Y-m-d',
        			value : DC.front.variable.SYS_CURRENTUSER.birthday
        	    },{
            		id : 'modifyUser_formPanel_note',
            		xtype : 'textarea',
            		height : 60,
        			name : 'userVOBean.notes',
        			fieldLabel : 'Notes',
        			value : DC.front.variable.SYS_CURRENTUSER.notes,
        			maxLength: 500,
	                maxLengthText : 'The length of the Notes cannot be more than 500.'
        	    }]
        }]
    }, config || {}));
	
};

Ext.extend(DC.front.ModifyUserFormPanel, Ext.form.FormPanel, {
    // 修改用户信息的响应事件
    modifyUserInfo: function(id) { // 修改当前用户
    	if (this.getForm().isValid()) {
    		this.getForm().submit({
                url: DC.url.MODIFYUSERINFO,
                success: function(form, action){
                	DC.util.CommonAction.unMask();
                	var res = action.result;
            		DC.action.SysAction.initUserInfo(res.user);
            		DC.obj.editor_tabPanel.getItem('editor_tabPanel_homePage').updateUserInfo();
            		Ext.getCmp("modify_userInfo_win").close();
            		Ext.example.msg('Prompt', res.msg, 'prompt');
                },
                failure: function(form, action){
                	DC.util.CommonAction.unMask();
                	switch (action.failureType) {
		                case Ext.form.Action.CLIENT_INVALID: // 当客户端验证失败时执行
		                     break;
		                case Ext.form.Action.CONNECT_FAILURE:
		                	 Ext.example.msg('Prompt Win', 'Network connection failure, so fail to commit.', 'error');
		                     break;
		                case Ext.form.Action.SERVER_INVALID: // 当服务器端的success属性的值返回false时执行
		                	 Ext.example.msg('Prompt Win', action.result.message, action.result.type);
		            }
                }
            });
    	}
    }
});